<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	
	function __construct(){
	 	
	 	parent::__construct();
	 	$this->load->library('encrypt');
	 	$this->load->helper('cookie');
	}
	
	function  login(){
		
		$sql = "SELECT * FROM users WHERE user_id = ? and password= ?"; 
		$para['user_id']= $_POST["name"];
		$key="#&$$&(&#fdafdauponjlnvcz";
		$para["password"]= $this->encrypt->sha1($_POST["psd"].$key);
		
		$data['users']=$this->db->query($sql,$para);
		
		if($data['users']->num_rows() > 0){
                 
			$this->session->set_userdata('user_id', $_POST["name"]);
			$this->session->set_userdata('msg', "");
		}else{
			$this->session->set_userdata('msg', "login first");
		}
		redirect('items/mainShow/');
	}
	
	function logout(){

		$this->session->unset_userdata('msg');
		$this->session->unset_userdata('user_id');
		redirect('items/mainShow/');
	}
	
	function register_view(){
		$this->load->view('users/register.php');
	}
	
	function register(){
		$para["user_id"]= $_POST["user_id"];
		$key="#&$$&(&#fdafdauponjlnvcz";
		$para["password"]= $this->encrypt->sha1($_POST["password"].$key);
		$para["user_name"]=$_POST["user_name"];
		$para["register_time"]= date('Y-m-d H:i:s');
		$para["recent_use"]= date('Y-m-d H:i:s');
		
		
		if($this->db->insert('users',$para)){
			$this->session->set_userdata('user_id',$_POST["user_id"]);
			$this->session->set_userdata('msg', "");
		}
		redirect('items/mainShow/');
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */